﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;


using PowerCreator.LMS.Web.Question;
using PowerCreator.LMS.Question.Entiry;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Common.Script;

public partial class sysadmin_QuestionManager_AddQuestionInfo_danx : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerCourseInfo courseInfoManager = new ManagerCourseInfo();
    //ManagerQuestionTypeInfo questionTypeManager = new ManagerQuestionTypeInfo();

    //ManagerQuestionInfo questionInfoManager = new ManagerQuestionInfo();
    
    ManagerQuestion objQuestion = new ManagerQuestion();
    Course objCourse = new Course();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!GetRole(Role.AddQuestion))
        //{
        //    Script.ShowAndHistory("您没有添加试题的权限!", -1);
        //    return;
        //}
        if (!IsPostBack)
        {
            ViewState["TypeID"] = 2;
            Pageload();
            bandList(3);
            ViewState["UserID"] = GetCreatedByInfo().UserID;
            //InitPage();
        }
    }
    //protected override void InitPage()
    //{
    //    lab_AddQuestionInfo_danx_QuestionType.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionType", PowerCreator.LMS.Language.LanagetItemType.Page);
        

    //    lab_AddQuestionInfo_danx_ContentTitle.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_ContentTitle", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    lab_AddQuestionInfo_danx_QuestionContent.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionContent", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    lab_AddQuestionInfo_danx_QuestionOption.Text = GetLanageValueByKey("lab_AddQuestionInfo_danx_QuestionOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        

    //    btn_Save.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    btn_Back.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);

    //    btn_AddQuestionInfo_danx_AddOptionC.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    btn_AddOptionD.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
    //    btn_AddOptionE.Text = GetLanageValueByKey("btn_AddQuestionInfo_danx_AddOption", PowerCreator.LMS.Language.LanagetItemType.Page);
        

    //    base.InitPage();
    //}
    private void Pageload()
    {
        DataTable dt_QuestionType = objQuestion.QueryQuestionType("");
        int rowindex_zuheti = 0;
        int rowindex_mingcijieshi = 0;
        for (int i = 0; i < dt_QuestionType.Rows.Count; i++)
        {
            if (dt_QuestionType.Rows[i]["QuestionTypeName"].ToString() == config.GetLanagerValueByKey("msg_CelueSelectQuest_zuheti", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rowindex_zuheti=i;
            }
            if (dt_QuestionType.Rows[i]["QuestionTypeName"].ToString() == config.GetLanagerValueByKey("lab_EditUserPaper_Question_Mingcijieshiti", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rowindex_mingcijieshi = i;
            }
        }
        dt_QuestionType.Rows.RemoveAt(rowindex_zuheti);
        dt_QuestionType.Rows.RemoveAt(rowindex_mingcijieshi);
       
        rbtn_QuestionType.DataSource = dt_QuestionType;

        rbtn_QuestionType.DataTextField = "QuestionTypeName";
        rbtn_QuestionType.DataValueField = "QuestionTypeID";
        
        rbtn_QuestionType.DataBind();
        for (int i = 0; i < rbtn_QuestionType.Items.Count; i++)
        {
            if (rbtn_QuestionType.Items[i].Text == config.GetLanagerValueByKey("msg_CelueSelectQuest_danxuanti", PowerCreator.LMS.Language.LanagetItemType.Page))
            {
                rbtn_QuestionType.Items[i].Selected = true;
            }
        }

    }
    private void bandList(int ItemCount)
    {
        ListItem objlist;
        for (int i = 0; i < ItemCount; i++)
        {
            objlist = new ListItem();
            switch (i)
            {
                case 0: objlist.Text = "A";
                    objlist.Selected = true;
                    break;
                case 1: objlist.Text = "B";
                    break;
                case 2: objlist.Text = "C";
                    break;
                case 3: objlist.Text = "D";
                    break;
                case 4: objlist.Text = "E";
                    break;
                case 5: objlist.Text = "F";
                    break;
            }
            objlist.Value = i.ToString();

     
        } 
    }
    private bool PageCheck()
    {

        return true;
    }
    private string ConvertOptionID(int Index)
    {
        string OptionID = string.Empty;
        switch (Index)
        {
            case 0: OptionID = "A";
                break;
            case 1: OptionID = "B";
                break;
            case 2: OptionID = "C";
                break;
            case 3: OptionID = "D";
                break;
            case 4: OptionID = "E";
                break;
            case 5: OptionID = "F";
                break;
        }
        return OptionID;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!PageCheck())
        {
            return;
        }
        
        VOQuestion voQuestion = new VOQuestion();
        voQuestion.QuestionIsFather = 0;
        voQuestion.FKQuestionCourseID = -1;
        voQuestion.QuestionCreateID = int.Parse(ViewState["UserID"].ToString());
        
        voQuestion.QuestionCreateTime = DateTime.Now;

        voQuestion.QuestionAnswer = "";        
        voQuestion.QuestionDefaultScore = 0;
        voQuestion.QuestionDiffculty = 0;
        voQuestion.QuestionKen = "";


        int quesiontClass = 2;                

        voQuestion.QuestionClass = quesiontClass;    
        voQuestion.QuestionContent = txt_QuestionContent.Text;
        voQuestion.QuestionParse = "";
        voQuestion.FKQuestionTypeID = int.Parse(ViewState["TypeID"].ToString());
        voQuestion.QuestionState = 2;         //禁用1,启用2

        ArrayList list = new ArrayList();

        ArrayList Optionlist = new ArrayList();
        Optionlist.Add(txt_OptionA.Text.Trim());
        Optionlist.Add(txt_OptionB.Text.Trim());
        Optionlist.Add(txt_OptionC.Text.Trim());
        Optionlist.Add(txt_OptionD.Text.Trim());
        Optionlist.Add(txt_OptionE.Text.Trim());
        Optionlist.Add(txt_OptionF.Text.Trim());


        //for (int i = 0; i < rbtn_answer.SelectedIndex+1; i++)
        //{
        //    string OptionID = ConvertOptionID(i);

        //    if (Optionlist[i].ToString() == "")
        //    {
        //        Script.Alert(Page, "msg", "选项" + OptionID + "不能为空!");
        //        return;
        //    }
        //}
        for (int i = 0; i < Optionlist.Count; i++)
        {
            string OptionID = ConvertOptionID(i);
            if (Optionlist[i].ToString() != "")
            {
                list.Add(OptionID + "、" + Optionlist[i].ToString());
            }
        }
        try
        {
            objQuestion.CreateQuestionOptionList(voQuestion, list);
            Script.ShowAndRedirect(this, config.GetLanagerValueByKey("msg_CelueSelectQuest_shuruti23", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
        catch
        {
            Script.ShowAndRedirect(this, config.GetLanagerValueByKey("msg_CelueSelectQuest_shuruti24", PowerCreator.LMS.Language.LanagetItemType.Page), "ManagerQuestionInfo.aspx");
        }
        
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("ManagerQuestionInfo.aspx");
    }
  
    protected void btn_AddOptionC_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "D";
        objlist.Value = "3";
        //rbtn_answer.Items.Add(objlist);
        Pnl_D.Visible = true;
        btn_AddQuestionInfo_danx_AddOptionC.Visible = false;
    }
    protected void btn_AddOptionD_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "E";
        objlist.Value = "4";
        //rbtn_answer.Items.Add(objlist);
        Pnl_E.Visible = true;
        btn_AddOptionD.Visible = false;
    }
    protected void btn_AddOptionE_Click(object sender, EventArgs e)
    {
        ListItem objlist = new ListItem();
        objlist.Text = "F";
        objlist.Value = "5";
        //rbtn_answer.Items.Add(objlist);
        Pnl_F.Visible = true;
        btn_AddOptionE.Visible = false;
    }
    protected void rdbtn_QuestionType_SelectedIndexChanged(object sender, EventArgs e)
    {
        string url = string.Empty;
        switch (rbtn_QuestionType.SelectedValue)
        {
            case "1":
                url = "AddQuestionInfo_panduan.aspx";
                break;
            case "2":
                url = "AddQuestionInfo_danx.aspx";
                break;
            case "3":
                url = "AddQuestionInfo_duox.aspx";
                break;
            case "4":
                url = "AddQuestionInfo_tiank.aspx";
                break;
            case "5":
                url = "AddQuestioninfo_mingci.aspx";
                break;
            case "6":
                url = "AddQuestionInfo_jianda.aspx";
                break;
            case "7":
                url = "AddQuestionInfo_zuhe.aspx";
                break;
       
        }
        Script.RedirectURL(url);
    }
}
